package gzhaoku.com.common.jobs;

import android.app.Activity;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import gzhaoku.com.common.Logger;
import gzhaoku.com.common.util.AppUpdate;

public class CheckUpdateJob implements Runnable{

    private static Logger log = Logger.getLog(CheckUpdateJob.class);

    final static ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);

    final static int Interval = 30 * 60;

    Activity context;



    public CheckUpdateJob(Activity context) {
        this.context = context;
    }

    public void doJob(){
        pool.schedule(this, 5, TimeUnit.SECONDS);
    }

    @Override
    public void run() {
        try{
            context.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    AppUpdate.checkUpdate(context);
                }
            });

        }catch (Exception e){
            log.e(e);
        }finally {
            pool.schedule(this, Interval, TimeUnit.SECONDS);
        }


    }
}
